<template>
  <div class="rechargeDetails">
    <el-card>
      <h4 class="title">工单记录</h4>
      <!-- 搜索 -->
      <el-form :inline="true" :model="rechargeData" class="demo-form-inline">
        <el-form-item
          label="用户名"
          v-if="this.$store.state.user.role == 'admin'"
        >
          <el-select
            size="medium"
            v-model="rechargeData.username"
            placeholder="请选择用户"
            clearable
          >
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.username"
              :value="item.username"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="日期：">
          <!-- :picker-options="pickerOptions" -->
          <el-date-picker
            size="medium"
            v-model="times"
            type="daterange"
            range-separator="-"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd HH:mm:ss"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="['00:00:00', '23:59:59']"
          >
          </el-date-picker>
          <el-button
            size="medium"
            type="primary"
            class="btn"
            @click="queryDetails"
            >查询明细</el-button
          >
        </el-form-item>
      </el-form>
      <!-- 表格内容 -->
      <el-table
        ref="multipleTable"
        :data="RechargeData.pageList"
        tooltip-effect="dark"
        style="width: 100%"
        border
      >
        <el-table-column type="index" align="center" width="50">
        </el-table-column>
        <!-- 审核状态 -->
        <el-table-column
          align="center"
          prop="status"
          width="150"
          label="处理状态"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span class="p3 pp" v-if="scope.row.status == '0'">
              <i class="el-icon-loading"></i> 待回复</span
            >
            <span class="p1 pp" v-if="scope.row.status == '1'">
              <i class="el-icon-success"></i> 已回复</span
            >
            <span class="p2 pp" v-if="scope.row.status == '2'"
              ><i class="el-icon-error"></i> 已驳回</span
            >
          </template>
        </el-table-column>

        <!-- 审核状态 -->
        <el-table-column prop="createTime" label="提交时间" align="center">
        </el-table-column>
        <el-table-column prop="username" label="提交用户" align="center">
        </el-table-column>
        <el-table-column prop="type" label="工单类型" align="center">
        </el-table-column>
        <el-table-column prop="title" label="工单标题" align="center">
        </el-table-column>

        <el-table-column prop="describes" label="问题描述" align="center">
        </el-table-column>

        <el-table-column label="工单截图" align="center">
          <template slot-scope="scope">
            <div class="rechargeDiv">
              <img
                :src="scope.row.image"
                alt=""
                width="100%"
                class="rechargeImg"
                @click="bigRechargeImg(scope.row.image)"
              />
            </div>
          </template>
        </el-table-column>

        <el-table-column prop="receipts" label="回复内容" align="center">
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <!-- currentPage -->
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 50, 100, 200]"
        :page-size="10"
        :current-page="rechargeData.pageNum"
        layout="total, sizes, prev, pager, next, jumper"
        :total="RechargeData.totalCount"
      >
      </el-pagination>
      <!-- 大图 -->
      <el-dialog :visible.sync="dialogVisible">
        <img width="100%" :src="dialogImageUrl" alt="" />
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import { getUsername } from "@/api/order";
import { getWorkOrder } from "@/api/titck";

// 引入防抖函数
import debounce from "lodash.debounce";
export default {
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() - 1000 * 60 * 60 * 12 > Date.now();
        },
      },
      //   搜索数据
      rechargeData: {
        username: "",
        pageNum: 1,
        pageSize: 10,
      },
      //   时间
      times: [],
      //   充值数据
      RechargeData: [],
      //   大图dialog
      dialogVisible: false,
      //   大图地址
      dialogImageUrl: "",
      srcList: [],
      // 下拉框
      options: [],
    };
  },
  async created() {
    this.getRechargeData();
    // 获取用户名
    let res = await getUsername();
    if (res.status == 0) {
      this.options = res.data;
    }
  },
  methods: {
    //   表格数据
    async getRechargeData() {
      if (this.times) {
        this.rechargeData.startTime = this.times[0];
        this.rechargeData.endTime = this.times[1];
      } else {
        this.rechargeData.startTime = "";
        this.rechargeData.endTime = "";
      }
      if (this.$store.state.user.role != "admin") {
        this.rechargeData.username = localStorage.getItem("username");
      }
      let res = await getWorkOrder(this.rechargeData);
      this.RechargeData = res.data;
      //   图片预览
      //   this.srcList = [];
      //   for (const item in res.data.pageList) {
      //     //  console.log(res.data.pageList[item].image);
      //     this.srcList.push(res.data.pageList[item].image);
      //   }
    },
    // 查询明细
    queryDetails: debounce(function () {
      this.rechargeData.pageNum = 1;
      this.getRechargeData();
    }, 500),
    // 分页查询
    async handleSizeChange(val) {
      this.rechargeData.pageSize = val;
      this.getRechargeData();
    },
    async handleCurrentChange(val) {
      this.rechargeData.pageNum = val;
      this.getRechargeData();
    },
    // 放大图片
    bigRechargeImg(imgsrc) {
      this.dialogImageUrl = imgsrc;
      this.dialogVisible = true;
    },
  },
};
</script>

<style lang="scss" scoped>
.rechargeDetails {
  .title {
    border-bottom: 1px solid #eee;
    padding-bottom: 20px;
  }
  .btn {
    margin-left: 20px;
  }
  .rechargeDiv {
    margin: 0 auto;
    width: 85px;
    height: 85px;
    border-radius: 10px;
    overflow: hidden;
    .rechargeImg {
      padding: 0;
      margin: 0;
      width: 100%;
    }
    .rechargeImg:hover {
      opacity: 0.5;
      cursor: pointer;
    }
  }

  .pp {
    display: inline-block;
    width: 80px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    color: #fff;
    font-size: 12px;
    border: 1px solid #e4e5e6;
  }
  .p1 {
    background-color: #85ce61;
    border-radius: 20px;
  }
  .p1 {
    background-color: #85ce61;
    border-radius: 20px;
  }
  .p2 {
    background-color: #f56c6c;
    border-radius: 20px;
  }
  .p3 {
    background-color: #666;
    border-radius: 20px;
  }
}
</style>
